/*
 * $Id: string.c,v 1.52 2006-03-05 17:23:21 bacon Exp $
 */

#if defined(__MSTRING)
#include <xp/bas/mstring.h>
#elif defined(__WSTRING)
#include <xp/bas/mstring.h>
#else
#include <xp/bas/string.h>
#endif

xp_size_t xp_strdel (xp_char_t* str, xp_size_t pos, xp_size_t n)
{
	xp_char_t* p = str, * q = str;
	xp_size_t idx = 0;

	while (*p != XP_CHAR('\0')) {
		if (idx < pos || idx >= pos + n) *q++ = *p;
		idx++; p++;
	}	

	*q = XP_CHAR('\0');
	return q - str;
}

xp_size_t xp_strxdel (xp_char_t* str, xp_size_t len, xp_size_t pos, xp_size_t n)
{
	xp_char_t* p = str, * q = str, * end = str + len;
	xp_size_t idx = 0;

	while (p < end) {
		if (idx < pos || idx >= pos + n) *q++ = *p;
		idx++; p++;
	}	

	return q - str;
}

xp_size_t xp_strrmchr (xp_char_t* str, xp_cint_t c)
{
	xp_char_t* p1, * p2;

	p1 = p2 = str;
	while (*p1 != XP_CHAR('\0')) {
		if (*p1 != c) *p2++ = *p1;
		p1++;
	}
	*p2 = XP_CHAR('\0');
	return p2 - str;
}

xp_size_t xp_strxrmchr (xp_char_t* str, xp_size_t len, xp_cint_t c)
{
	xp_char_t* p1, * p2, * end;

	p1 = p2 = str;
	end = p1 + len;
	while (p1 < end) {
		if (*p1 != c) *p2++ = *p1;
		p1++;
	}
	return p2 - str;
}

